
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tathata.Common.BLL.Entities;
using Tathata.Common.BLL.Managers;
using Tathata.Common.Utils;

namespace Tathata.Web.Administration
{
    public partial class Administration_CategoryTemplateDetails : BaseNopAdministrationPage
    {
        private void BindData()
        {
            CategoryTemplate categoryTemplate = CategoryTemplateManager.GetByCategoryTemplateID(this.CategoryTemplateID);
            if (categoryTemplate != null)
            {
                this.txtName.Text = categoryTemplate.Name;
                this.txtTemplatePath.Text = categoryTemplate.TemplatePath;
                this.txtDisplayOrder.Value = categoryTemplate.DisplayOrder;
                this.lblCreatedOn.Text = categoryTemplate.CreatedOn.ToString();
                this.lblUpdatedOn.Text = categoryTemplate.UpdatedOn.ToString();
            }
            else
                Response.Redirect("CategoryTemplates.aspx");
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.BindData();
            }
        }

        protected void SaveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    CategoryTemplate categoryTemplate = CategoryTemplateManager.GetByCategoryTemplateID(this.CategoryTemplateID);

                    if (categoryTemplate != null)
                    {
                        categoryTemplate = CategoryTemplateManager.UpdateCategoryTemplate(categoryTemplate.CategoryTemplateID, txtName.Text,
                            txtTemplatePath.Text, txtDisplayOrder.Value, categoryTemplate.CreatedOn, DateTime.Now);
                        Response.Redirect("CategoryTemplateDetails.aspx?CategoryTemplateID=" + categoryTemplate.CategoryTemplateID.ToString());
                    }
                    else
                        Response.Redirect("CategoryTemplates.aspx");
                }
                catch (Exception exc)
                {
                    ProcessException(exc);
                }
            }
        }

        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            try
            {
                CategoryTemplateManager.DeleteCategoryTemplate(this.CategoryTemplateID);
                Response.Redirect("CategoryTemplates.aspx");
            }
            catch (Exception exc)
            {
                ProcessException(exc);
            }
        }

        public int CategoryTemplateID
        {
            get
            {
                return CommonHelper.QueryStringInt("CategoryTemplateID");
            }
        }
    }
}
